
var inject = {
	injectCustomJS(path: string) {
		var temp = document.createElement('script');
		temp.setAttribute('type', 'text/javascript');
		// 获得的地址类似：chrome-extension://ihcokhadfjfchaeagdoclpnjdiokfakg/js/inject.js
		temp.src = chrome.extension.getURL(path);
		temp.onload = function (this: any) {
			// 放在页面不好看，执行完后移除掉
			this.parentNode.removeChild(this);
		};
		document.head.appendChild(temp);
	},
	injectCustomCSS(path: string) {
		var temp = document.createElement('link');
		temp.href = chrome.extension.getURL(path);
		temp.rel = "stylesheet";
		document.head.appendChild(temp);
	},
	injectJS(url: string) {
		var temp = document.createElement('script');
		temp.setAttribute('type', 'text/javascript');
		temp.src = url;
		temp.onload = function (this: any) {
			this.parentNode.removeChild(this);
		};
		document.head.appendChild(temp);
	},

	injectHTML(html: string, className:string, id?: string) {
		var temp = document.createElement('div');
		temp.className = className;
		id && (temp.id = id);
		temp.innerHTML = html;
		document.body.appendChild(temp);
	},

	injectCSS(url: string) {
		var temp = document.createElement('link');
		temp.href = url;
		temp.rel = "stylesheet";
		document.body.appendChild(temp);
	}
}

export { inject };
export const $ = document.querySelector.bind(document);
export const $$ = document.querySelectorAll.bind(document);